package com.chenchen.tiguan.venue.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.chenchen.tiguan.venue.domain.VenueCourt;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenchen.tiguan.common.annotation.Log;
import com.chenchen.tiguan.common.core.controller.BaseController;
import com.chenchen.tiguan.common.core.domain.AjaxResult;
import com.chenchen.tiguan.common.enums.BusinessType;
import com.chenchen.tiguan.venue.domain.VenueTimeSlot;
import com.chenchen.tiguan.venue.service.IVenueTimeSlotService;
import com.chenchen.tiguan.common.utils.poi.ExcelUtil;
import com.chenchen.tiguan.common.core.page.TableDataInfo;

/**
 * 预生成的场地可预约时间段Controller
 * 
 * @author chenchen
 * @date 2025-04-14
 */
@RestController
@RequestMapping("/venue/timeslot")
public class VenueTimeSlotController extends BaseController
{
    @Autowired
    private IVenueTimeSlotService venueTimeSlotService;

    /**
     * 查询预生成的场地可预约时间段列表
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:list')")
    @GetMapping("/list")
    public TableDataInfo list(VenueTimeSlot venueTimeSlot,@Param("courtName") String courtName,@Param("date") @JsonFormat(pattern = "yyyy-MM-dd") Date date)
    {
        VenueCourt venueCourt = new VenueCourt();
        venueCourt.setCourtName(courtName);
        venueTimeSlot.setVenueCourt(venueCourt);
        startPage();
        System.out.println(date);
        List<VenueTimeSlot> list = venueTimeSlotService.selectVenueTimeSlotList(venueTimeSlot);
        return getDataTable(list);
    }

    /**
     * 导出预生成的场地可预约时间段列表
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:export')")
    @Log(title = "预生成的场地可预约时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VenueTimeSlot venueTimeSlot)
    {
        List<VenueTimeSlot> list = venueTimeSlotService.selectVenueTimeSlotList(venueTimeSlot);
        ExcelUtil<VenueTimeSlot> util = new ExcelUtil<VenueTimeSlot>(VenueTimeSlot.class);
        util.exportExcel(response, list, "预生成的场地可预约时间段数据");
    }

    /**
     * 获取预生成的场地可预约时间段详细信息
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:query')")
    @GetMapping(value = "/{slotId}")
    public AjaxResult getInfo(@PathVariable("slotId") Long slotId)
    {
        return success(venueTimeSlotService.selectVenueTimeSlotBySlotId(slotId));
    }

    /**
     * 新增预生成的场地可预约时间段
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:add')")
    @Log(title = "预生成的场地可预约时间段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VenueTimeSlot venueTimeSlot)
    {
        return toAjax(venueTimeSlotService.insertVenueTimeSlot(venueTimeSlot));
    }

    /**
     * 修改预生成的场地可预约时间段
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:edit')")
    @Log(title = "预生成的场地可预约时间段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VenueTimeSlot venueTimeSlot)
    {
        return toAjax(venueTimeSlotService.updateVenueTimeSlot(venueTimeSlot));
    }

    /**
     * 删除预生成的场地可预约时间段
     */
    @PreAuthorize("@ss.hasPermi('venue:timeslot:remove')")
    @Log(title = "预生成的场地可预约时间段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{slotIds}")
    public AjaxResult remove(@PathVariable Long[] slotIds)
    {
        return toAjax(venueTimeSlotService.deleteVenueTimeSlotBySlotIds(slotIds));
    }


}
